package com.mall.user.service.impl;

import com.mall.user.model.UserInfo;
import com.mall.user.mapper.UserInfoMapper;
import com.mall.user.service.IUserInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author Darren
 * @since 2022-08-29
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements IUserInfoService {
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addUserInfo(UserInfo userinfo){
        return super.save(userinfo);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteById(String username){
        return super.removeById(username);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateUserInfo(UserInfo userinfo){
        return super.updateById(userinfo);
    }

    @Override
    public UserInfo getById(String username){
        return super.getById(username);
    }

    @Override
    public List<UserInfo> selectList(UserInfo userinfo){
        return super.list(getQueryWrapper(userinfo));
    }

    @Override
    public Page<UserInfo> selectPage(Page<UserInfo> page, UserInfo userinfo){
        return super.page(page, getQueryWrapper(userinfo));
    }

    public LambdaQueryWrapper<UserInfo> getQueryWrapper(UserInfo userinfo){
        return Wrappers.<UserInfo>lambdaQuery()
            .eq(ObjectUtils.isNotEmpty(userinfo.getUsername()), UserInfo::getUsername, userinfo.getUsername())
            .eq(ObjectUtils.isNotEmpty(userinfo.getPassword()), UserInfo::getPassword, userinfo.getPassword())
            .eq(ObjectUtils.isNotEmpty(userinfo.getPhone()), UserInfo::getPhone, userinfo.getPhone())
            .eq(ObjectUtils.isNotEmpty(userinfo.getEmail()), UserInfo::getEmail, userinfo.getEmail())
            .eq(ObjectUtils.isNotEmpty(userinfo.getCreated()), UserInfo::getCreated, userinfo.getCreated())
            .eq(ObjectUtils.isNotEmpty(userinfo.getUpdated()), UserInfo::getUpdated, userinfo.getUpdated())
            .eq(ObjectUtils.isNotEmpty(userinfo.getSourceType()), UserInfo::getSourceType, userinfo.getSourceType())
            .eq(ObjectUtils.isNotEmpty(userinfo.getNickName()), UserInfo::getNickName, userinfo.getNickName())
            .eq(ObjectUtils.isNotEmpty(userinfo.getName()), UserInfo::getName, userinfo.getName())
            .eq(ObjectUtils.isNotEmpty(userinfo.getStatus()), UserInfo::getStatus, userinfo.getStatus())
            .eq(ObjectUtils.isNotEmpty(userinfo.getHeadPic()), UserInfo::getHeadPic, userinfo.getHeadPic())
            .eq(ObjectUtils.isNotEmpty(userinfo.getQq()), UserInfo::getQq, userinfo.getQq())
            .eq(ObjectUtils.isNotEmpty(userinfo.getIsMobileCheck()), UserInfo::getIsMobileCheck, userinfo.getIsMobileCheck())
            .eq(ObjectUtils.isNotEmpty(userinfo.getIsEmailCheck()), UserInfo::getIsEmailCheck, userinfo.getIsEmailCheck())
            .eq(ObjectUtils.isNotEmpty(userinfo.getSex()), UserInfo::getSex, userinfo.getSex())
            .eq(ObjectUtils.isNotEmpty(userinfo.getUserLevel()), UserInfo::getUserLevel, userinfo.getUserLevel())
            .eq(ObjectUtils.isNotEmpty(userinfo.getPoints()), UserInfo::getPoints, userinfo.getPoints())
            .eq(ObjectUtils.isNotEmpty(userinfo.getExperienceValue()), UserInfo::getExperienceValue, userinfo.getExperienceValue())
            .eq(ObjectUtils.isNotEmpty(userinfo.getBirthday()), UserInfo::getBirthday, userinfo.getBirthday())
            .eq(ObjectUtils.isNotEmpty(userinfo.getLastLoginTime()), UserInfo::getLastLoginTime, userinfo.getLastLoginTime())
            .eq(ObjectUtils.isNotEmpty(userinfo.getProvinceid()), UserInfo::getProvinceid, userinfo.getProvinceid())
            .eq(ObjectUtils.isNotEmpty(userinfo.getCityid()), UserInfo::getCityid, userinfo.getCityid())
            .eq(ObjectUtils.isNotEmpty(userinfo.getAreaid()), UserInfo::getAreaid, userinfo.getAreaid())
        ;
    }
}
